package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.jaya.budan.R;
import com.jaya.budan.bean.User_Information;
import com.jaya.budan.utils.ToolUtils;


public class Fill_Information2_Adapter extends BaseAdapter {

    private Context mcontext;
    private User_Information user_information;
    private int mtype, select = -1;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
    }

    public Fill_Information2_Adapter(Context context, User_Information list, int type) {
        user_information = list;
        mcontext = context;
        mtype = type;
    }

    @Override
    public int getCount() {
        if (mtype == 1) {
            return user_information.getType().size();
        } else if (mtype == 2) {
            return user_information.getRole().size();
        } else if (mtype == 3) {
            return user_information.getFace().size();
        } else if (mtype == 4) {
            return user_information.getStyle().size();
        } else if (mtype == 5) {
            return user_information.getWork().size();
        } else if (mtype == 7) {
            return user_information.getIdentity().size();
        } else if (mtype == 8) {
            return user_information.getStatus().size();
        } else if (mtype == 9) {
            return user_information.getFace().size();
        } else {
            return user_information.getAim().size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mtype == 1) {
            return user_information.getType().get(position);
        } else if (mtype == 2) {
            return user_information.getRole().get(position);
        } else if (mtype == 3) {
            return user_information.getFace().get(position);
        } else if (mtype == 4) {
            return user_information.getStyle().get(position);
        } else if (mtype == 5) {
            return user_information.getWork().get(position);
        } else if (mtype == 7) {
            return user_information.getIdentity().get(position);
        } else if (mtype == 8) {
            return user_information.getStatus().get(position);
        } else if (mtype == 9) {
            return user_information.getFace().get(position);
        } else {
            return user_information.getAim().get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint({"SetTextI18n", "ViewHolder"})
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView.inflate(mcontext, R.layout.fill_gridview_item, null);
        TextView tv_fill_gv_item = view.findViewById(R.id.tv_fill_gv_item);
        RelativeLayout rl_fill_gv_item = view.findViewById(R.id.rl_fill_gv_item);
        if (mtype == 1) {
            tv_fill_gv_item.setText("" + user_information.getType().get(position).getName());
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getType().get(position).getName().equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 2) {
            tv_fill_gv_item.setText("" + user_information.getRole().get(position).getName());
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getRole().get(position).getName().equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 3) {
            tv_fill_gv_item.setText("" + user_information.getFace().get(position).getName());
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getFace().get(position).getName().equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 4) {
            tv_fill_gv_item.setText("" + user_information.getStyle().get(position).getName());
            if (user_information.getStyle().get(position).isChecked()) {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
            } else {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
            }
        } else if (mtype == 5) {
            tv_fill_gv_item.setText("" + user_information.getWork().get(position));
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getWork().get(position).equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 7) {
            tv_fill_gv_item.setText("" + user_information.getIdentity().get(position));
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getIdentity().get(position).equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 8) {
            tv_fill_gv_item.setText("" + user_information.getStatus().get(position).getName());
            if (!ToolUtils.isEmpty(name)) {
                if (user_information.getStatus().get(position).getName().equals(name)) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            } else {
                if (position == select) {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
                } else {
                    rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
                }
            }
        } else if (mtype == 9) {
            tv_fill_gv_item.setText("" + user_information.getFace().get(position).getName());
            if (user_information.getFace().get(position).isChecked()) {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
            } else {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
            }
        } else {
            tv_fill_gv_item.setText("" + user_information.getAim().get(position).getName());
            if (user_information.getAim().get(position).isChecked()) {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_login);
            } else {
                rl_fill_gv_item.setBackgroundResource(R.drawable.login_exit);
            }
        }
        return view;
    }
}
